package com.fruitstore.jdbc2.dao.impl;

import com.fruitstore.jdbc2.dao.FruitDao;
import com.fruitstore.jdbc2.dao.base.BaseDao;
import com.fruitstore.jdbc2.pojo.Fruit;
import java.util.List;
// 实现数据库CRUD操作
public class FruitDaoImpl extends BaseDao<Fruit> implements FruitDao {


    @Override
    public List<Fruit> getFruitList() {
        String sql = "select * from t_fruit";
        return super.executeQuery(sql);
    }

    @Override
    public boolean addFruit(Fruit fruit) {
        String sql = "insert into t_fruit values(0,?,?,?,?)";
        int count = super.executeUpdate(sql,fruit.getFname(),fruit.getPrice(),fruit.getFcount(),fruit.getFname());
        System.out.println("返回："+count);
        return count>0;
    }

    @Override
    public boolean updateFruit(Fruit fruit) {
        String sql = "update t_fruit set fcount = ? where fid = ?";
        return super.executeUpdate(sql, fruit.getFcount(),fruit.getFid())>0;
    }

    @Override
    public boolean delFruit(String name) {
        String sql = "delete from t_fruit where fname like ?";
        return super.executeUpdate(sql,name)>0;
    }

    @Override
    public Fruit getFruitByFname(String fname) {
        String sql = "select * from t_fruit where fname=?";
        return super.load(sql,fname);
    }
}
